# -*- coding: utf-8 -*-
#环形双链

class RoundLinkNode(object):
    
    def __init__(self,item=None,nextp=None,previousp=None):
        #数据项
        self.item=item
        #指向下一个节点引用
        self.nextp=nextp 
        #指向前一个节点的引用
        self.previousp=previousp


class RoundLinkChain(object):
    
    def __init__(self):
        self.head=None
        self.length=0
        
    def append(self,v:RoundLinkNode):
        if(self.length==0):
            self.head=v
            v.nextp=self
            v.previousp=self
            self.length=1
        else:
            #获取当前末尾节点
            lastp=self.head.previousp
            lastp.nextp=v
            v.nextp=self.head
            self.head.previousp=v
            v.previousp=lastp
            self.length=self.length+1
    
    def __len__(self):
        return self.length
    
    #删除第i个节点
    def remove(self,i:int):
        i=i%self.length
        currentp=self.head
        for j in range(i):
            currentp=currentp.nextp
        return currentp

rlc=RoundLinkChain()
for i in range(10):
    rln=RoundLinkNode(i*i)
    rlc.append(rln)
